package com.demo.user;

import com.demo.common.model.User;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.kit.Kv;

public class UserController extends Controller {
    @Inject
    UserService userService;
    public void login(){
        User user = getBean(User.class);
        boolean res = userService.login(user);
        if (res == true){
            render("/mis/admin.html");
        }else {
            renderJson("wrong");
        }
    }

    public void list(){
        renderJson(Kv.by("code",0).set("data",userService.list()));
    }

    public void addUser(){
        User user = getBean(User.class);
        userService.addUser(user);
        renderJson(Kv.by("msg","success"));
    }

    public void delUser(){
        User user = getBean(User.class,"");
        userService.delUser(user);
        renderJson(Kv.by("msg","success"));
    }
}
